﻿#region Using Declarations

    using System;

    using Csla;

    using MarketPulse.BusinessLogic.Core;
    using MarketPulse.BusinessLogic.Common.Criteria;

#endregion

namespace MarketPulse.BusinessLogic.Common
{
    [Serializable]
    [Csla.Server.ObjectFactory("MarketPulse.DataAccess.Factory.AreaFactory, MarketPulse.DataAccess.Factory", "FetchInfo")]
    public class AreaInfo : MarketPulseReadOnlyBase<AreaInfo>
    {
        #region Constructor(s)

            /// <summary>
            /// Default constructor is private in order to (try to) enforce construction
            /// only via the static factory methods provided.
            /// </summary>
            private AreaInfo()
            {
            }

        #endregion

        #region Methods

            #region Factory Methods

                /// <summary>
                /// 
                /// </summary>
                /// <param name="areaGUID"></param>
                /// <returns></returns>
                public static AreaInfo Get(System.Guid areaGUID)
                {
                    return DataPortal.Fetch<AreaInfo>(new SingleCriteria<Guid>(areaGUID));
                }

            #endregion

        #endregion

        #region Properties

            /// <summary>
            /// The CountryGUID property
            /// </summary>
            public static PropertyInfo<System.Guid> CountryGUIDProperty = RegisterProperty<System.Guid>(p => p.CountryGUID, string.Empty);
            public System.Guid CountryGUID
            {
                get{ return GetProperty(CountryGUIDProperty); } }

            /// <summary>
            /// The ParentAreaGUID property
            /// </summary>
            public static PropertyInfo<System.Guid?> ParentAreaGUIDProperty = RegisterProperty<System.Guid?>(p => p.ParentAreaGUID, string.Empty, (System.Guid?)null);
            public System.Guid? ParentAreaGUID
            {
                get
                {
                    return GetProperty(ParentAreaGUIDProperty);
                }
            }

            /// <summary>
            /// The AreaName property
            /// </summary>
            public static PropertyInfo<System.String> AreaNameProperty = RegisterProperty<System.String>(p => p.AreaName, string.Empty);
            public System.String AreaName
            {
                get
                {
                    return GetProperty(AreaNameProperty);
                }
            }

            /// <summary>
            /// The AreaCode property
            /// </summary>
            public static PropertyInfo<System.String> AreaCodeProperty = RegisterProperty<System.String>(p => p.AreaCode, string.Empty, (System.String)null);
            public System.String AreaCode
            {
                get
                {
                    return GetProperty(AreaCodeProperty);
                }
            }

            /// <summary>
            /// The Parent Area Info
            /// </summary>
            public static PropertyInfo<AreaInfo> ParentAreaInfoProperty = RegisterProperty<AreaInfo>(p => p.ParentAreaInfo);
            public AreaInfo ParentAreaInfo
            {
                get
                {
                    // If the property hasn't been loaded yet
                    if (!FieldManager.FieldExists(ParentAreaInfoProperty) && (ParentAreaGUID != null))
                    {
                        LoadProperty(ParentAreaInfoProperty, AreaInfo.Get((Guid)ParentAreaGUID));
                        OnPropertyChanged(ParentAreaInfoProperty);
                        return ReadProperty(ParentAreaInfoProperty);
                    }
                    else
                    {
                        // Return the current property
                        return GetProperty(ParentAreaInfoProperty);
                    }
                }
            }

        #endregion
    }
}